package com.letu.mq.listener;

import com.letu.mq.model.MySimpleMessage;
import com.letu.mq.service.BusinessPointService;
import com.letu.mq.service.CheckTopicTagServer;
import com.letu.mq.util.MessageExtUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description: 单个业务类型发送
 */
@Slf4j
//@Component
//@RocketMQMessageListener(topic = "${rocketmq.consumer.businessPointTopic}", consumerGroup = "${spring.application.name}-${spring.profiles.active}",
//        selectorExpression = "${rocketmq.tags}",
//        messageModel = MessageModel.CLUSTERING, consumeMode = ConsumeMode.ORDERLY)
public class BusinessPointListner implements RocketMQListener<MySimpleMessage>, RocketMQPushConsumerLifecycleListener {

    @Autowired
    private BusinessPointService businessPointService;

    @Override
    public void onMessage(MySimpleMessage message) {
        businessPointService.execute(message);
    }

    @Override
    public void prepareStart(DefaultMQPushConsumer consumer) {

        // 设置最大重试次数
        consumer.setMaxReconsumeTimes(4);
    }
}
